package com.kbbywyclient.ui.activity;

import android.os.Handler;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

import com.kbbywyclient.R;
import com.kbbywyclient.di.AppComponent;
import com.kbbywyclient.presenter.base.BasePresenter;
import com.kbbywyclient.ui.activity.base.BaseActivity;
import com.kbbywyclient.util.ActivitySkipUtil;

import java.util.HashMap;
import java.util.Map;
import butterknife.BindView;

/**
 * Description:
 * Created by FHW
 * on 2017/4/5
 */

public class WelcomeActivity extends BaseActivity implements Animation.AnimationListener {
    @BindView(R.id.iv_welcome)
    ImageView iv_welcome;

    Animation welcome_alpha;//动画

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_welcome;
    }

    @Override
    protected void initView() {
        setScreenName("启动页");
        welcome_alpha = new AnimationUtils().loadAnimation(this, R.anim.welcome_alpha);
        showDefault();
    }

    private void showDefault() {
        iv_welcome.setImageResource(R.mipmap.img_welcome);
        welcome_alpha.setFillEnabled(true); //启动Fill保持
        welcome_alpha.setFillAfter(true);  //设置动画的最后一帧是保持在View上面
        iv_welcome.setAnimation(welcome_alpha);
        welcome_alpha.setAnimationListener(WelcomeActivity.this);  //为动画设置监听
    }

    @Override
    public void initData() {
        Map<String,String> bigDataMap = new HashMap<>();
        bigDataMap.put("behavior","cbeibei_app_start");
        BasePresenter presenter=new BasePresenter();
        presenter.bigDataBuried(bigDataMap);
    }

    @Override
    public void initAppComponent(AppComponent appComponent) {

    }

    @Override
    public void onAnimationStart(Animation animation) {

    }

    @Override
    public void onAnimationEnd(Animation animation) {
        handler.sendEmptyMessageDelayed(1, 1000);
    }

    private Handler handler = new Handler(msg -> {
        ActivitySkipUtil.skipAnotherActivity(WelcomeActivity.this, MainActivity.class);
        finish();
        return false;
    });


    @Override
    public void onAnimationRepeat(Animation animation) {

    }
}
